package com.test.hm;

import java.util.BitSet;

public class BitSetDemo {

	public static void main(String[] args) {
		BitSet bits1 = new BitSet(16);
		BitSet bits2 = new BitSet(16);

		for (int i = 0; i < 16; i++) {
			if ((i % 2) == 0)bits1.set(i);
			if ((i % 5) == 0)bits2.set(i);
		}
		System.out.println("Initial pattern in bits1: ");
		System.out.println(bits1);
		System.out.println("\nInitial pattern in bits2: ");
		System.out.println(bits2);
		int ibits2 = bits2.cardinality();
		System.out.println(ibits2);
		
		
		bits2.and(bits1);
		System.out.println("\nbits2 AND bits1: ");
		System.out.println(bits2);
		
		System.out.println();
		int ibits1 = bits1.cardinality();
		ibits2 = bits2.cardinality();
		System.out.println(ibits1);
		System.out.println(ibits2);
		
	}

}
